#include "ServerCoordinator.h"




void AliveMsg::serialize(std::stringstream &ss)
{
	Message::serialize(ss);
	serverName.serialize(ss);
}

void AliveMsg::deSerialize(std::stringstream & ss)
{
	Message::deSerialize(ss);
	serverName.deSerialize(ss);
}


void AliveRet::serialize(std::stringstream &ss)
{
	Message::serialize(ss);


    ss<<serverList.size()<<" ";
	std::list<ServerInfo>::iterator itSI = serverList.begin(); 
	for(;itSI!=serverList.end();itSI++)
		itSI->serialize(ss);

	ss<<taskList.size()<<" ";
	std::list<Task>::iterator itTL = taskList.begin();
	for(;itTL != taskList.end(); itTL++)
		itTL->serialize(ss);

	ss<<doneTaskList.size()<<" ";
	std::list<TaskInfo>::iterator itDTL = doneTaskList.begin();
	for( ;itDTL != doneTaskList.end(); itDTL++)
		itDTL->serialize(ss);
	
}

void AliveRet::deSerialize(std::stringstream &ss)
{
	serverList.clear();
	taskList.clear();
	Task task;
	ServerInfo serverInfo;
	TaskInfo taskInfo;
	int listSize;

	ss>>listSize;
	for(int i = 0 ; i < listSize;i++)
	{
		serverInfo.deSerialize(ss);
		serverList.push_front(serverInfo);
	}

	ss>>listSize;
	for(int i = 0; i< listSize;i++)
	{
		task.deSerialize(ss);
		taskList.push_front(task);
	}

	ss>>listSize;
	for(int i = 0; i< listSize;i++)
	{
		taskInfo.deSerialize(ss);
		doneTaskList.push_front(taskInfo);
	}
	
}

void TaskRegistration::serialize(std::stringstream & ss)
{
	Message::serialize(ss);
	serverName.serialize(ss);
	task.serialize(ss);
	ss<<ID<<" ";
}

void TaskRegistration::deSerialize(std::stringstream & ss)
{
	Message::deSerialize(ss);
	serverName.deSerialize(ss);
	task.deSerialize(ss);
	ss>>ID;
}

void TaskRegistrationRet::serialize(std::stringstream & ss)
{
	Message::serialize(ss);
	taskInfo.serialize(ss);
	serverName.serialize(ss);
}

void TaskRegistrationRet::deSerialize(std::stringstream & ss)
{
	Message::deSerialize(ss);
	taskInfo.deSerialize(ss);
	serverName.deSerialize(ss);
}

void TaskStatusChange::serialize(std::stringstream & ss)
{
	Message::serialize(ss);
	taskInfo.serialize(ss);
	name.serialize(ss);
}

void TaskStatusChange::deSerialize(std::stringstream &ss)
{
	Message::deSerialize(ss);
	taskInfo.deSerialize(ss);
	name.deSerialize(ss);
}